import actions from './../actions/user';
import * as types from './../types/user';

import {
    Profile,
    UserState,
    LoginUser
} from './../interface/user';

export default {
    actions,
    state: {
        profile: {} as UserState,
        loginUser: {} as LoginUser
    },
    mutations: {
        [types.onLogin](
            state: UserState,
            playLoad: LoginUser
        ) {
            const {
                token,
                loginname,
                avatar_url
            } = playLoad;
            state.loginUser = {
                loginname,
                avatar_url,
                token
            }
        },
        [types.getUserProfile](
            state: UserState,
            playLoad: Profile
        ) {
            const {
                profile
            } = state;
            const {
                loginname
            } = playLoad;
            profile[loginname] = playLoad;
            state.profile = {...profile};
        }
    }
}